package com.hgyc.mom.data.controller;

import com.hgyc.mom.base.entity.Material;
import com.hgyc.mom.base.service.MaterialService;
import com.hgyc.mom.common.constant.CacheConstants;
import com.hgyc.mom.common.redis.RedisCache;
import com.hgyc.mom.mes.vo.LineInProductVO;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 车间生产看板
 * @author fwj
 * @since 2025/3/18
 */
@RestController
@RequestMapping("/mes/data/workshop")
public class WorkshopProductController {

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private MaterialService materialService;

    @Operation(summary = "产线当前生产产品", description = "产线当前生产产品")
    @GetMapping("/inProduct/{lineId}")
    private List<LineInProductVO> lineInProduct(@PathVariable("lineId") Long lineId) {
        LineInProductVO lineInProductVO = redisCache.getCacheObject(CacheConstants.LINE_IN_PRODUCT_DATA_CACHE + lineId, LineInProductVO.class);
        if (lineInProductVO != null && lineInProductVO.getMaterialId() != null) {
            Material productingMaterial = materialService.getById(lineInProductVO.getMaterialId());
            lineInProductVO.setLineId(lineId);
            lineInProductVO.setMaterialCode(productingMaterial.getMaterialCode());
            lineInProductVO.setMaterialName(productingMaterial.getMaterialName());
            lineInProductVO.setMaterialSpec(productingMaterial.getSpec());
        }
        List<LineInProductVO> list = new ArrayList<>();
        list.add(lineInProductVO);
        return list;
    }


}
